"use strict";

module.exports = (app) => {
  const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize;

  const ProductImage = app.model.define("product_image", {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    product_id: {
      type: INTEGER,
      allowNull: false,
      comment: "商品ID",
    },
    image_url: {
      type: STRING(255),
      allowNull: false,
      comment: "图片URL",
    },
    sort_order: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "排序",
    },
    // is_cover: {
    //   type: BOOLEAN,
    //   allowNull: false,
    //   defaultValue: false,
    //   comment: "是否封面",
    // },
    created_at: DATE,
    updated_at: DATE,
  });

  // 关联关系
  ProductImage.associate = function () {
    // 图片与商品：多对一关系
    app.model.ProductImage.belongsTo(app.model.Product, {
      foreignKey: "product_id",
    });
  };

  return ProductImage;
};
